﻿using Geeno.API.Model;
using Geeno.API.Services;
using Geeno.Common;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;

namespace Geeno.API.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IOrderService orderService;

        public WeatherForecastController(ILogger<WeatherForecastController> logger
            , IOrderService orderService)
        {
            _logger = logger;
            this.orderService = orderService;
        }

        /// <summary>
        /// 返回温度列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var items = new List<Item>
            {
                new Item { ID=1, ItemName="jack", Price=120},
                new Item { ID=12, ItemName="jack2", Price=120},
                new Item { ID=13, ItemName="jack3", Price=120},
            };
            ExcelNpoiUtil.CreateBook(items, @"E:/demo.xlsx");
            var rng = new Random();
            _logger.LogDebug("debug1111");
            _logger.LogInformation("info2222");
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>

        [HttpPost]
        [Produces("application/json")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public IEnumerable<Order> GetOrders([FromBody] Order order)
        {

            orderService.GetItemsM();

            return new List<Order>();
        }

        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IEnumerable<Item> GetItems()
        {
            var rlt = orderService.GetItems();
            return rlt;
        }


        [HttpPost]
        [Produces("application/json")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public Order GetSingleOrder()
        {
            var rps = new Order();
            orderService.GetSingleOrder();
            return rps;
        }

        [HttpPost]
        [Produces("application/json")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public int GetExecuteScalar()
        {
            var rps = 0;
            orderService.GetExecuteScalar();
            return rps;
        }

        [HttpPost]
        [Produces("application/json")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public int DelExecute()
        {
            var rps = 0;
            orderService.DelExecute();
            return rps;
        }

        [HttpPost]
        public int TestDate()
        {
            var m = orderService.TestDate();
            return 0;
        }
        [HttpPost]
        public string SayHello(string nickName)
        {
            _logger.Info("test");
            return $"hello {nickName}";
        }
    }
}
